package com.starmark.gateway.auth.security.command;


import com.alibaba.fastjson.JSON;
import com.starmark.gateway.auth.security.config.GatewayProjectConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 网关工程初始化配置,
 * 后续会将其做为一个功能,做成类似多租户的功能
 *
 * @author starmark
 * @date 20-1-23  上午9:44
 */
@Component
public class GatewayProjectConfigInitCommand implements CommandLineRunner {


    private static final String STARMARK_GATEWAY_PROJECT = "starmark:gateway:project:info:";

    @Autowired
    @Lazy
    private GatewayProjectConfig gatewayProjectConfig;

    @Autowired
    @Lazy
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void run(String... args) {

        //加载项目配置,保证登陆系统不需要修改
        stringRedisTemplate.opsForValue().set(STARMARK_GATEWAY_PROJECT + gatewayProjectConfig.getProjectCode(), JSON.toJSONString(gatewayProjectConfig));


    }
}
